package com.qilu.pe.ui.activity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.qilu.pe.R;
import com.qilu.pe.base.Base2Activity;
import com.qilu.pe.base.BaseResult2;
import com.qilu.pe.base.Global;
import com.qilu.pe.dao.bean.AiExplain;
import com.qilu.pe.dao.http.APIRetrofit;
import com.qilu.pe.support.util.ActiviceCollector;
import com.ruitu.arad.api.RxUtil;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;
import com.ruitu.arad.util.ToastUtils;

import java.util.List;

import io.reactivex.functions.Consumer;

/**
 * <br/>┏------------------------------------------
 * <br/>│Note:
 * <br/>│
 * <br/>┣------------------------------------------
 * <br/>│                 /) /)
 * <br/>│               ฅ(• ﻌ •)ฅ
 * <br/>│  Created by @author HaoKing on 2020/11/07 11:45.
 * <br/>│          www.muchenxinxi.com
 * <br/>│           www.nextdever.com
 * <br/>│           WeChat: NextDever
 * <br/>│             QQ: 773693552
 * <br/>│     QQ Group: Geek Chat 344386592
 * <br/>┗------------------------------------------
 */
public class AiExpertDetailsActivity extends AppCompatActivity implements View.OnClickListener {

    String mOrderId;
    AiListAdapter mAdapter;
    RecyclerView vList;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ai_expert_details);
        ActiviceCollector.addActivity(this);
        initView();
        initData();
    }

    public void initView() {
        findViewById(R.id.vBack).setOnClickListener(this);
        mAdapter = new AiListAdapter(this);
        vList = findViewById(R.id.vRecycler);
        vList.setLayoutManager(new LinearLayoutManager(this));
        vList.setAdapter(mAdapter);
    }

    public void initData() {
        mOrderId = getIntent().getStringExtra("orderId");

        APIRetrofit.getDefault().getAiReportDetails(Global.HEADER, mOrderId)
                .compose(RxUtil.<BaseResult2<List<AiExplain>>>subIoObMain())
                .subscribe(new Consumer<BaseResult2<List<AiExplain>>>() {
                    @Override
                    public void accept(BaseResult2<List<AiExplain>> res) throws Exception {
                        if (res.isSuccess()) {
                            mAdapter.setDataList(res.getData());
                        } else {
                            ToastUtils.showShort(res.getMsg());
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                });
    }

    private class AiListAdapter extends ListBaseAdapter<AiExplain> {

        public AiListAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_ai_search_list;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            TextView tv_name = holder.getView(R.id.tv_name);
            TextView tv_abridge = holder.getView(R.id.tv_abridge);
            TextView tv_range = holder.getView(R.id.tv_range);
            TextView tv_sig = holder.getView(R.id.tv_sig);

            AiExplain ai = mDataList.get(position);
            tv_name.setText(ai.getName());
            tv_abridge.setText(ai.getEnglish());
            tv_range.setText(ai.getScope());
            tv_sig.setText(ai.getSignificance());
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.vBack:
                finish();
                break;
        }
    }
}
